const mongoose = require('mongoose');
require('dotenv').config();

async function checkProductImages() {
  try {
    await mongoose.connect(process.env.MONGODB_URI || 'mongodb://localhost:27017/jpshop');
    console.log('MongoDB连接成功');
    
    const Product = require('./src/models/product.model');
    
    // 获取前5个商品的图片信息
    const products = await Product.find({}).limit(5).select('name mainImage images');
    
    console.log('商品图片信息:');
    products.forEach((product, index) => {
      console.log(`${index + 1}. ${product.name}`);
      console.log(`   mainImage: ${product.mainImage}`);
      console.log(`   images: ${JSON.stringify(product.images)}`);
      console.log('');
    });
    
    process.exit(0);
  } catch (err) {
    console.error('数据库连接失败:', err);
    process.exit(1);
  }
}

checkProductImages();
